package Backtracking;

import java.util.ArrayList;
import java.util.List;

public class _784_LetterCasePermutation {
    List<String> results = new ArrayList<>();
    int length = 0;
    String originalS = null;
    public List<String> letterCasePermutation(String S) {
        this.length = S.length();
        this.originalS = S;
        getEveryPermutation(0,"");
        return results;
    }

    public void getEveryPermutation(int pos,String s) {
        if (s.length() == length) {
            results.add(s);
        } else {
            char tempC = originalS.charAt(pos);
            if (Character.isDigit(tempC)) {
                getEveryPermutation(pos+1,s+tempC);
            } else {
                if (Character.isLowerCase(tempC)) {
                    getEveryPermutation(pos+1,s+Character.toUpperCase(tempC));
                } else {
                    getEveryPermutation(pos+1,s+ Character.toLowerCase(tempC));
                }
                getEveryPermutation(pos+1,s+tempC);
            }
        }
    }
}
